package com.gf.controller.order;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gf.bean.GetorderInfo;
import com.gf.service.impl.OrderrServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/*
*展示自己的抢到的订单的数据的servlet
* */

@WebServlet(name = "ShowmygetorderServlet",urlPatterns = "/showmygetorders")
public class ShowmygetorderServlet extends HttpServlet {
    static OrderrServiceImpl orderimpl = null;
    static {
        orderimpl=new OrderrServiceImpl();


    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        int userid =(int) request.getSession().getAttribute("userid");
        //获取当前session保存的userid
        List<GetorderInfo> orderrs = orderimpl.selectmysendorders(userid);
        //通过userid来获取所有我送的订单并返回成集合
        JSONObject backjson = new JSONObject();
        //新建json对象
        //设置正确的响应码和信息
        response.setStatus(200);
        backjson.put("status", 200);
        backjson.put("data", orderrs);
        //打印输出
        out.println(JSON.toJSON(backjson));
        out.flush();
        out.close();


    }
}
